<?php

namespace App;

abstract class Controller
{
    protected $defaultController = 'index';

    protected $defaultAction = 'default';

    protected $filter = null;
    protected $view = null;
    protected $request = null;
    protected $response = null;
    protected $db = null;
    protected $hook = null;
    protected $session = null;

    const INIT_REQUEST  = 1;
    const INIT_RESPONSE = 2;
    const INIT_VIEW     = 4;
    const INIT_DB       = 8;
    const INIT_SESSION  = 16;
    const INIT_HOOK     = 32;
    const INIT_FILTER      = 64; //filter ://比如权限控制,
    /*
    class LoginFilter extends App\Controller\Filter
    {
        public function before()
        {
            if ($login_ok)
            {
                retur true;
            }
            else
            {
                return false;
            }
        }

        public function after(){}
    }


    */

    protected function init()
    {
        /*
            $request;
            $response; 即为视图 View
            $session;
            $database;
            $interceptor; 拦截器
            $hooks; 钩子
            $filter; 可能等同于 $interceptor 尚未确定
        */
    }


    public function start($action = '')
    {
        if ($this->filter !== null)
        {
            $this->filter->before();
            $this->{$action}();
            $this->filter->after();
        }
        else
        {
            $this->{$action}();
        }
    }

    public function __destruct()
    {
        echo "<hr/>", round(microtime(1) - SYS_INIT_TIME, 8);
    }
}
